﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterClinicaSanPablo.Master" AutoEventWireup="true"
    EnableEventValidation="false" CodeBehind="RegistroNoConformidad.aspx.cs" Inherits="ClinicaSanPablo.RegistroNoConformidad" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <script type="text/javascript">

        $(document).ready(function () {

            $("#lblAuditoria").hide("slow");
            $("#txtAuditoria").hide("slow");
            $("#lblFechaAuditoria").hide("slow");
            $("#txtFecha").hide("slow");

            function validar() {
                $('#registroNoConformidad').validate({
                    rules: {
                        ctl00$master$txtDescripcion: {
                            required: true
                        }
                    },
                    messages: {
                        ctl00$master$txtDescripcion: {
                            required: "<br/> * Ingrese descripcion"
                        }
                    }
                });
            }


            $(document).ready(function () {
                $("#txtFecha").datepicker();
            });

            $.ajax({
                type: "POST",
                url: "RegistroNoConformidad.aspx/ComboOrigen",
                data: {},
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var jsonData = JSON.parse(data.d);
                    $("#cmbOrigen").get(0).options.length = 0;
                    $.each(jsonData,
                    function (index, item) {
                        $("#cmbOrigen").get(0).options[$("#cmbOrigen").get(0).options.length] = new Option(item.DesOrigen, item.CodOrigen);
                    });
                    $('#cmbOrigen').removeAttr('disabled');
                },
                error: function () {
                    alert("Failed to load names");
                }
            });


            $.ajax({
                type: "POST",
                url: "RegistroNoConformidad.aspx/ComboArea",
                data: {},
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    var models = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
                    myarray = new Array;

                    for (var i = 0; i < models.length; i++) {
                        myarray[i] = new Array();
                        var val = models[i].CodArea;
                        var text = models[i].DesArea;
                        var text2 = models[i].Mailjefearea;
                        myarray[i][0] = val;
                        myarray[i][1] = text2;
                        $("#cmbAreaInvolucrada").get(0).options[$("#cmbAreaInvolucrada").get(0).options.length] = new Option(text, val);
                    }
                },
                error: function (response) {
                    if (response.length != 0)
                        alert(response);
                }
            });

            $("#cmbAreaInvolucrada").change(function () {
                var codTipSeg = $("#cmbAreaInvolucrada option:selected").val();
                for (var a = 0; a < myarray.length; a++) {
                    if (codTipSeg == myarray[a][0]) {
                        var correo = myarray[a][1];
                    }
                }
                $("#txtcorreo").val(correo);
            });


            $.ajax({
                type: "POST",
                url: "RegistroNoConformidad.aspx/ComboRequisito",
                data: {},
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var jsonData = JSON.parse(data.d);
                    $("#cmbRequisito").get(0).options.length = 0;
                    $.each(jsonData,
                    function (index, item) {
                        $("#cmbRequisito").get(0).options[$("#cmbRequisito").get(0).options.length] = new Option(item.DesRequisito, item.CodRequisito);
                    });
                    $('#cmbRequisito').removeAttr('disabled');
                },
                error: function () {
                    alert("Failed to load names");
                }
            });

            $.ajax({
                type: "POST",
                url: "RegistroNoConformidad.aspx/ComboArea",
                data: {},
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var jsonData = JSON.parse(data.d);
                    $("#cmbOtrasAreas").get(0).options.length = 0;
                    $.each(jsonData,
                    function (index, item) {
                        $("#cmbOtrasAreas").get(0).options[$("#cmbOtrasAreas").get(0).options.length] = new Option(item.DesArea, item.CodArea);
                    });
                    $('#cmbOtrasAreas').removeAttr('disabled');
                },
                error: function () {
                    alert("Failed to load names");
                }
            });

            $("#cmbOrigen").change(function () {

                var codOrigen = $("#cmbOrigen option:selected").val();
                if (codOrigen == "ORI003") {
                    $("#lblAuditoria").show("slow");
                    $("#txtAuditoria").show("slow");
                    $("#lblFechaAuditoria").show("slow");
                    $("#txtFecha").show("slow");
                }
                else {
                    $("#lblAuditoria").hide("slow");
                    $("#txtAuditoria").hide("slow");
                    $("#lblFechaAuditoria").hide("slow");
                    $("#txtFecha").hide("slow");
                }
            });

            $("#Btnenviar").click(function () {

                var mailGe = $("#txtcorreo").val();
                var mailA1 = ($('#ChA1:checked').val() !== undefined) ? $("#hidCorreo2").val() : "";
                var mailA2 = ($('#ChA2:checked').val() !== undefined) ? $("#hidCorreo3").val() : "";
                var mailA3 = ($('#ChA3:checked').val() !== undefined) ? $("#hidCorreo4").val() : "";
                var mailA4 = ($('#ChA4:checked').val() !== undefined) ? $("#hidCorreo5").val() : "";
                var codigo = $("#idcod").val();

                var data4 = {
                    EGerente: mailGe,
                    EA1: mailA1,
                    EA2: mailA2,
                    EA3: mailA3,
                    EA4: mailA4,
                    codigo: codigo
                };

                var jsondata = JSON.stringify(data4);
                $.ajax({
                    type: "POST",
                    url: "RegistroNoConformidad.aspx/DerivarNC",
                    data: jsondata,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        var jsonData = JSON.parse(data.d);
                        if (jsonData.resultado)
                            alert("envio mensaje");
                        else
                            alert("no envio mensaje");
                    },
                    error: function () {
                        alert("Failed to load names");
                    }
                });
                return false;
            });


            $("#btnDerivar").click(function () {
                var vp = $("#idcod").val();
                if (vp != 0) {
                    if ($("#cmbAreaInvolucrada").val() != 0) {
                        var data1 = { codigoNC: vp };
                        var jsondata = JSON.stringify(data1);
                        $.ajax({
                            type: "POST",
                            url: "BusPaciente.aspx/Buscar_DerivarNC",
                            data: jsondata,
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (data) {
                                var jsonData = JSON.parse(data.d);
                                if (jsonData.resultado) {
                                    $("#TxtCorreo1").val($("#txtcorreo").val());
                                    $("#TxtCorreo2").val(jsonData.correo1);
                                    $("#TxtCorreo3").val(jsonData.correo2);
                                    $("#TxtCorreo4").val(jsonData.correo3);
                                    $("#TxtCorreo5").val(jsonData.correo4);
                                    $("#hidCorreo2").val(jsonData.correo1);
                                    $("#hidCorreo3").val(jsonData.correo2);
                                    $("#hidCorreo4").val(jsonData.correo3);
                                    $("#hidCorreo5").val(jsonData.correo4);
                                }
                            },
                            error: function () {
                                alert("Failed to load names");
                            }
                        });

                        $("#Derivar").simpledialog("open");
                        return false;
                    }
                } else alert("Primero tiene que registrar antes de derivar");
                return false;




            });

            $("#BtnSalir").click(function () {
                $("#Derivar").simpledialog("close");
            });

            $("#Derivar").simpledialog({
                autoOpen: false,
                resizable: false,
                modal: true,
                height: 350,
                width: 350,
                close: function (event, ui) {
                }
            });

            $("#btnLimpiar").click(function () {
                $("#txtDescripcion").val("");
                $("#txtAuditoria").val("");
                $("#cmbOrigen").val("0");
                $('#cmbOrigen').get(0).selectedIndex = 0;
                $('#cmbAreaInvolucrada').get(0).selectedIndex = 0;
                $('#cmbRequisito').get(0).selectedIndex = 0;
                $("#txtDescripcion").focus();
                return false;
            });

            $("#btnRegistrar").click(function () {
                validar();
            });

        });
 

    </script>
    <style type="text/css">
        .error
        {
            border: 1px solid red;
        }
        label.error
        {
            border: 0px;
            color: Red;
        }
        div.container
        {
            display: none;
            color: Red;
        }
        #grdMuestraRecla
        {
            text-align: center;
        }
        #asd .ui-jqgrid
        {
            display: block;
            margin: 0 auto;
        }
        .style36
        {
            width: 51px;
        }
        .style37
        {
            width: 3px;
            height: 26px;
        }
        .style38
        {
            width: 75px;
        }
        .style39
        {
            width: 182px;
        }
        .style40
        {
            height: 26px;
        }
        .style41
        {
            width: 51px;
            height: 26px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="master" runat="server">
    <form id="registroNoConformidad" runat="server">
    <div class="cuerpo">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td colspan="3">
                    <img src="images/caja_main01.gif" width="973" height="13" />
                </td>
            </tr>
            <tr>
                <td width="7" background="images/caja_main02.gif">
                    &nbsp;
                </td>
                <td class="info" valign="top">
                    <h1>
                        Registro de <strong>La No Conformidad</strong></h1>
                    <div class="content" id="page-2">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="TablaStyle">
                            <tr>
                                <td width="6">
                                </td>
                                <td>
                                </td>
                                <td width="6">
                                </td>
                            </tr>
                            <tr>
                                <td width="6">
                                    &nbsp;
                                </td>
                                <td bgcolor="#eeeeee">
                                    <table width="93%" border="0" align="center" cellpadding="4" cellspacing="4">
                                        <tr>
                                            <td>
                                                Fecha:&nbsp;&nbsp;&nbsp;<b><%= DateTime.Now.ToShortDateString() %></b>
                                            </td>
                                            <td align="right">
                                                <asp:Button ID="btnBuscar" runat="server" Text="Buscar" CssClass="submitBtn"/>
                                                &nbsp;
                                            </td>
                                            <td>
                                                &nbsp;
                                            </td>
                                        </tr>
                                        <tr>
                                            <td valign="top" colspan="3">
                                                Descripción:
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="3">
                                                <asp:TextBox ID="txtDescripcion" runat="server" Height="79px" TextMode="MultiLine"
                                                    Width="818px"></asp:TextBox>
                                            </td>
                                        </tr>
                                    </table>
                                    <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" />
                                    <asp:HiddenField ID="idcod" runat="server" Value="0" />
                                    <asp:HiddenField ID="txtcorreo" runat="server" />
                                    <asp:HiddenField ID="hidCorreo2" runat="server" />
                                    <asp:HiddenField ID="hidCorreo3" runat="server" />
                                    <asp:HiddenField ID="hidCorreo4" runat="server" />
                                    <asp:HiddenField ID="hidCorreo5" runat="server" />
                                    <table width="90%" border="0" align="center" cellpadding="4" cellspacing="4">
                                        <tr>
                                            <td width="90">
                                                Origen:
                                            </td>
                                            <td class="style38">
                                                <asp:DropDownList ID="cmbOrigen" runat="server" Height="22px" Width="150px">
                                                </asp:DropDownList>
                                            </td>
                                            <td class="style39">
                                                Área Involucrada:
                                            </td>
                                            <td>
                                                <asp:DropDownList ID="cmbAreaInvolucrada" runat="server" Height="22px" Width="150px">
                                                </asp:DropDownList>
                                            </td>
                                            <td align="right" class="style36">
                                                Requisito:
                                            </td>
                                            <td>
                                                <asp:DropDownList ID="cmbRequisito" runat="server" Height="22px" Width="200px">
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="style36">
                                                <asp:Label ID="lblAuditoria" runat="server" Text="Auditoria:"></asp:Label>
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtAuditoria" runat="server" CssClass="frm" Width="150px"></asp:TextBox>
                                            </td>
                                            <td class="style39">
                                                <asp:Label ID="lblFechaAuditoria" runat="server" Text="Fecha Auditoria:"></asp:Label>
                                            </td>
                                            <td>
                                                <asp:TextBox ID="txtFecha" runat="server" CssClass="frm" Width="104px"></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="4" class="style40">
                                                <strong>Otros Involucrados:</strong>
                                            </td>
                                            <td align="right" class="style37" colspan="2">
                                            </td>
                                            <td class="style41">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td valign="top">
                                                Área:
                                            </td>
                                            <td valign="top" class="style38" colspan="5">
                                                <asp:DropDownList ID="cmbOtrasAreas" runat="server" Height="22px" Width="200px">
                                                </asp:DropDownList>
                                                <asp:UpdatePanel runat="server" ID="updGrid" UpdateMode="Conditional" colspan="3">
                                                    <ContentTemplate>
                                                        <asp:Button ID="btnAgregar" runat="server" Text="Agregar" CssClass="submitBtn" OnClick="btnAgregar_Click" />
                                                        <asp:Label ID="lblMensajeAdd" runat="server" ForeColor="Red"></asp:Label>
                                                        </td> </tr>
                                                        <tr>
                                                            <td>
                                                                &nbsp;
                                                            </td>
                                                            <td colspan="5">
                                                                <asp:GridView ID="gvOtrasAreas" runat="server" CellPadding="3" Font-Bold="False"
                                                                    Font-Size="11px" Height="16px" Width="592px" BackColor="#CCCCCC" BorderColor="#CCCCCC"
                                                                    Font-Overline="False" Font-Strikeout="False" Font-Underline="False" ForeColor="#333333"
                                                                    EnableTheming="True" ViewStateMode="Enabled" AutoGenerateColumns="False" OnRowDeleting="gvOtrasAreas_RowDeleting">
                                                                    <AlternatingRowStyle BackColor="White" ForeColor="#333333" />
                                                                    <Columns>
                                                                        <asp:BoundField DataField="Codigo" HeaderText="Codigo" />
                                                                        <asp:BoundField DataField="Area" HeaderText="Area" />
                                                                        <asp:BoundField DataField="Jefe" HeaderText="Jefe" />
                                                                        <asp:CommandField ButtonType="Image" DeleteImageUrl="~/images/ico_cancelar.png" ShowDeleteButton="True" />
                                                                    </Columns>
                                                                    <EditRowStyle BackColor="#999999" />
                                                                    <FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
                                                                    <HeaderStyle BackColor="#E3F1FA" Font-Bold="False" ForeColor="#2779AA" Wrap="True"
                                                                        Font-Overline="False" Font-Size="11px" Font-Strikeout="False" Font-Underline="False"
                                                                        HorizontalAlign="Center" />
                                                                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                                                    <RowStyle BackColor="#F9FAFB" BorderStyle="Double" ForeColor="#333333" Font-Overline="False"
                                                                        HorizontalAlign="Center" />
                                                                    <SelectedRowStyle BackColor="#F9FAFB" Font-Bold="True" ForeColor="#333333" Wrap="True" />
                                                                    <SortedAscendingCellStyle BackColor="#E9E7E2" ForeColor="#333333" />
                                                                    <SortedAscendingHeaderStyle BackColor="Silver" />
                                                                    <SortedDescendingCellStyle BackColor="#FFFDF8" />
                                                                    <SortedDescendingHeaderStyle BackColor="#6F8DAE" ForeColor="#333333" />
                                                                </asp:GridView>
                                                    </ContentTemplate>
                                                </asp:UpdatePanel>
                                            </td>
                                            <td class="style36">
                                                &nbsp;
                                            </td>
                                            <td class="style36">
                                                &nbsp;
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td width="6">
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="6">
                                </td>
                                <td>
                                </td>
                                <td width="6">
                                </td>
                            </tr>
                        </table>
                    </div>
                    <p align="center">
                        <asp:Button ID="btnRegistrar" runat="server" Text="Registrar" CssClass="submitBtn"
                            OnClick="btnRegistrar_Click" />
                        <button id="btnCancelar" class="submitBtn">
                            <span>Cancelar</span></button>
                        <button id="btnLimpiar" class="submitBtn">
                            <span>Limpiar</span></button>
                        <button id="btnDerivar" class="submitBtn">
                            <span>Derivar</span></button>
                    </p>
                </td>
                <td width="7" background="images/caja_main03.gif">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <img src="images/caja_main04.gif" width="973" height="13" />
                </td>
            </tr>
        </table>
    </div>
    <div id="Derivar">
        <div>
            <h2>
                Derivar La No Conformidad</h2>
            <table width="90%" border="0" cellspacing="1" cellpadding="2">
                <tr>
                    <td class="style27" colspan="3">
                        Derivar a los siguientes correos:
                    </td>
                </tr>
                <tr>
                    <td class="style29">
                        &nbsp;
                    </td>
                    <td class="style34">
                        Correo jefe de área:
                    </td>
                    <td class="style31">
                        &nbsp;
                    </td>
                    <td class="style30">
                    </td>
                </tr>
                <tr>
                    <td class="style29">
                        &nbsp;
                    </td>
                    <td class="style34">
                        <asp:TextBox ID="TxtCorreo1" runat="server" ReadOnly="True" Width="223px" Enabled="False"></asp:TextBox>
                    </td>
                    <td class="style31">
                        <asp:CheckBox ID="ChGerente" runat="server" />
                    </td>
                    <td class="style30">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td class="style28">
                        &nbsp;&nbsp;
                    </td>
                    <td class="style33">
                        Correos de áreas involucradas:
                    </td>
                    <td class="style32">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td class="style28">
                        &nbsp;
                    </td>
                    <td class="style33">
                        <asp:TextBox ID="TxtCorreo2" runat="server" ReadOnly="True" Width="223px" Enabled="False"></asp:TextBox>
                    </td>
                    <td class="style32">
                        <asp:CheckBox ID="Chjefe" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="style28">
                        &nbsp;&nbsp;&nbsp;
                    </td>
                    <td class="style33">
                        <asp:TextBox ID="TxtCorreo3" runat="server" ReadOnly="True" Width="223px" Enabled="False"></asp:TextBox>
                    </td>
                    <td class="style32">
                        <asp:CheckBox ID="ChGestor" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="style28">
                        &nbsp;&nbsp;
                    </td>
                    <td class="style33">
                        <asp:TextBox ID="TxtCorreo4" runat="server" ReadOnly="True" Width="223px" Enabled="False"></asp:TextBox>
                    </td>
                    <td class="style32">
                        <asp:CheckBox ID="ChSupervisor" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="style28">
                        &nbsp;&nbsp;
                    </td>
                    <td class="style33">
                        <asp:TextBox ID="TxtCorreo5" runat="server" ReadOnly="True" Width="223px" Enabled="False"></asp:TextBox>
                    </td>
                    <td class="style32">
                        <asp:CheckBox ID="ChEncargado" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="style28">
                        &nbsp;
                    </td>
                    <td class="style33">
                        &nbsp;
                    </td>
                    <td class="style32">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td class="style28">
                        &nbsp;
                    </td>
                    <td class="style33">
                        &nbsp;
                    </td>
                    <td class="style32">
                        &nbsp;
                    </td>
                </tr>
            </table>
            <table width="80%" border="0" cellspacing="1" cellpadding="2" align="center">
                <tr>
                    <td align="center">
                        <button id="Btnenviar" value="buscarReclamante" class="submitBtn">
                            <span>Enviar</span></button>
                        <button id="BtnSalir" value="closeModal" class="submitBtn" style="margin-right: 0px;">
                            <span>Salir</span></button>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    </form>
</asp:Content>
